﻿<phone:PhoneApplicationPage 
    x:Class="USSDRunner.MessagePage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:USSDRunner="clr-namespace:USSDRunner"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="PortraitOrLandscape"
    Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="696" d:DesignWidth="480"
    shell:SystemTray.IsVisible="True">

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <USSDRunner:TitleControl Grid.Row="0" PageTitle="Message" />

        <!--ContentPanel - place additional content here-->
        <ScrollViewer Grid.Row="1" >
            <Grid Margin="{StaticResource PageContentMargin}">
                <Grid.Resources>
                    <Style x:Key="TextBlockStyle" TargetType="TextBlock" BasedOn="{StaticResource PhoneTextTitle3Style}">
                        <Setter Property="VerticalAlignment" Value="Center" />
                        <Setter Property="MinWidth" Value="140" />
                    </Style>
                </Grid.Resources>
            
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" /> <!-- Title -->
                    <RowDefinition Height="Auto" /> <!-- Message body (main message part) -->
                    <RowDefinition Height="Auto" /> <!-- Parameters -->
                    <RowDefinition Height="Auto" /> <!-- Add parameter button -->
                    <RowDefinition Height="Auto" /> <!-- Remove parameter button -->
                    <RowDefinition Height="Auto" /> <!-- Full USSD message -->
                    <RowDefinition Height="Auto" /> <!-- Send message button -->
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <TextBlock Grid.Row="0" Grid.Column="0" Text="Title:" Style="{StaticResource TextBlockStyle}" />
                <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Path=Title, Mode=TwoWay}" />

                <TextBlock Grid.Row="1" Grid.Column="0" Text="Message:" Style="{StaticResource TextBlockStyle}" />
                <TextBox
                    Grid.Row="1" Grid.Column="1"
                    InputScope="TelephoneNumber" KeyUp="HandleMessageTextBoxKeyUp">
                    <TextBox.Text>
                        <Binding
                            Mode="TwoWay"
                            Path="Body.Text"
                            NotifyOnValidationError="true" ValidatesOnExceptions="true" />
                    </TextBox.Text>
                </TextBox>

              <ItemsControl Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" ItemsSource="{Binding Path=Parameters}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Column="0" Text="{Binding Path=Label}" Style="{StaticResource TextBlockStyle}" />
                                <TextBox Grid.Column="1" Text="{Binding Path=Text, Mode=TwoWay}" InputScope="TelephoneNumber"  KeyUp="HandleMessageTextBoxKeyUp" />
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

                <TextBlock Grid.Row="5" Grid.Column="0" Text="Full message:" Style="{StaticResource TextBlockStyle}" />
                <TextBox Grid.Row="5" Grid.Column="1" Text="{Binding FullMessage, Mode=OneWay}" IsReadOnly="True" />
            </Grid>
        </ScrollViewer>
    </Grid>
 
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton x:Name="AddButton" IconUri="/Images/appbar.new.rest.png" Text="Add" Click="HandleAddParameterButtonClick" />
            <shell:ApplicationBarIconButton x:Name="RemoveButton"  IconUri="/Images/appbar.minus.rest.png" Text="Remove" Click="HandleRemoveParameterButtonClick" />
            <shell:ApplicationBarIconButton x:Name="SendButton" IconUri="/Images/appbar.next.rest.png" Text="Send" Click="HandleSendMessageButtonClick" />
            <shell:ApplicationBarIconButton x:Name="ClearButton" IconUri="/Images/appbar.cancel.rest.png" Text="Clear" Click="HandleClearButtonClick" />
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

</phone:PhoneApplicationPage>
